// login module
import { makeAutoObservable } from 'mobx';
import { http, setToken, getToken, removeToken } from '@/utils';

class LoginStore {
  token = getToken() || '';

  constructor() {
    makeAutoObservable(this);
  }

  async getToken({ mobile, code }) {
    const res = await http.post('http://geek.itheima.net/v1_0/authorizations', {
      mobile,
      code,
    });
    this.token = res.data.token;
    // 存入localstorage
    setToken(this.token);
  }

  logout() {
    removeToken();
  }
}

export default LoginStore;
